package me.xplabs.scene 
{
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import me.xplabs.constant.GameResultType;
	import me.xplabs.Globals;
	import me.xplabs.interfaces.IScene;
	import me.xplabs.msg.NotificationFight;
	import me.xplabs.msg.NotificationName;
	import me.xplabs.view.FailGameView;
	import me.xplabs.view.WinGameView;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	/**
	 * ...
	 * @author xiaohan
	 */
	public class EndSceneMediator extends Mediator implements IScene 
	{
		public static const NAME:String = "EndSceneMediator";
		private var _container:Sprite;
		private var _isInit:Boolean;
		
		
		private var _failGameView:FailGameView;
		private var _winGameView:WinGameView;
		public function EndSceneMediator(viewComponent:Object=null) 
		{
			super(NAME, viewComponent);
			
		}
		
		private function init():void 
		{
			if (_isInit) return;
			_isInit = true;
			_container = new Sprite();

			_failGameView = new FailGameView(_container);
			_winGameView = new WinGameView(_container);
		}
		public function show():void 
		{
			init();
			print("显示结束视图");
			DisplayObjectContainer(viewComponent).addChild(_container);
			
			
		}
		
		public function dispose():void 
		{
			print("销毁结束视图");
			if (DisplayObjectContainer(viewComponent).contains(_container)) 
				DisplayObjectContainer(viewComponent).removeChild(_container);
				
			_failGameView.hide();
			_winGameView.hide();
		}
		
		public function get container():Sprite 
		{
			return _container;
		}
		override public function handleNotification(notification:INotification):void 
		{
			switch(notification.getName())
			{
				case NotificationName.END_GAME:
					show();
					if (int(notification.getBody()) == GameResultType.FAIL)
					{
						_failGameView.show();
						_failGameView.setXY(Globals.centerW - _failGameView.width * .5, Globals.centerH - _failGameView.height * .5);
					}else
					{
						//_failGameView.show();
						//_failGameView.setXY(Globals.centerW - _failGameView.width * .5, Globals.centerH - _failGameView.height * .5);
						_winGameView.show();
						_winGameView.setXY(Globals.centerW - _winGameView.width * .5, Globals.centerH - _winGameView.height * .5);
					}
					break;
				case NotificationName.HIDE_END_GAME:
					dispose();
					break;
			}
		}
		override public function listNotificationInterests():Array 
		{
			return [NotificationName.END_GAME, NotificationName.HIDE_END_GAME];
		}
		
	}

}